home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / gui / pmdev.lha / PopupMenuDeveloper / Demos / SimpleMenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-22  |  2.6 KB  |  93 lines

  1. //
  2. // $VER: SimpleMenu.c 2.0 (22.8.97)
  3. //
  4. // Popup Menu example program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // Run and click the mouse in the window!
  10. //
  11.  
  12. #include <intuition/intuition.h>
  13.  
  14. #include <clib/intuition_protos.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/alib_protos.h>
  17.  
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21.  
  22. #include <libraries/pm.h>
  23. #include <proto/pm.h>
  24.  
  25. struct IntuitionBase    *IntuitionBase;
  26. struct GfxBase        *GfxBase;
  27. struct PopupMenuBase    *PopupMenuBase;
  28.  
  29. struct Window *w;    // This window is only needed to find out when and where the menu should appear.
  30.             // The font in this window's rastport will be used for the menu.
  31.  
  32. void main()
  33. {
  34.     BOOL r=TRUE;
  35.     struct IntuiMessage *im,imsg;
  36.     struct PopupMenu *p;
  37.  
  38.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  39.     if(PopupMenuBase) {
  40.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  41.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  42.  
  43.         p=PMMenu("Trashcan"),
  44.             PMItem("Open"),                    PMEnd,
  45.             PMItem("Information..."),            PMEnd,
  46.             PMBar,                        PMEnd,
  47.             PMItem("Snapshot"),                PMEnd,
  48.             PMItem("UnSnapshot"),                PMEnd,
  49.             PMBar,                        PMEnd,
  50.             PMItem("Leave out"),                PMEnd,
  51.             PMItem("Rename..."),                PMEnd,
  52.             PMItem("Delete"),                PMEnd,
  53.             PMBar,                        PMEnd,
  54.             PMItem("Empty"),    PM_UserData,    5,    PMEnd,
  55.             End;
  56.  
  57.         if(p) {
  58.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,    // Open a little window
  59.                     WA_RMBTrap,    TRUE,
  60.                     WA_DragBar,    TRUE,
  61.                     WA_Width,    150,
  62.                     WA_Height,    100,
  63.                     WA_Left,    150,
  64.                     WA_Top,        0,
  65.                     WA_Title,    "SimpleMenu",
  66.                     WA_CloseGadget,    TRUE,
  67.                     TAG_DONE);
  68.             if(w) {
  69.                 while(r) {
  70.                     WaitPort(w->UserPort);                        // Wait for a message
  71.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  72.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  73.                         ReplyMsg((struct Message *)im);                // Reply the message
  74.  
  75.                         switch(imsg.Class) {
  76.                             case IDCMP_CLOSEWINDOW: r=FALSE; break;
  77.                             case IDCMP_MOUSEBUTTONS:            // The user has hit a mousebutton - time to open the menu!
  78.                                 r=(BOOL)((ULONG)(PM_OpenPopupMenu(w,
  79.                                         PM_Menu,        p,
  80.                                         PM_Code,        imsg.Code,    // Must always be there!
  81.                                         TAG_DONE))-5);
  82.                             break;
  83.                         }
  84.                     }
  85.                 }
  86.                 CloseWindow(w);
  87.             } else printf("Window error!\n");
  88.             PM_FreePopupMenu(p);
  89.         } else printf("Menu error!\n");
  90.         CloseLibrary((struct Library *)PopupMenuBase);
  91.     }
  92. }
  93.